<?php

/*
 * This script belongs to Aspect PHP.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * This script is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details.
 */

/**
 * The contract for an AOP pointcut filter
 *
 * @package    aspectPhp
 * @subpackage lib
 * @author     gboisse
 */
abstract class aspectPointcutFilter {

    /** @var string The name of the aspect class */
    protected $aspectClassName;
    /** @var string The name of the advice method to be executed if $pointcutPattern matches */
    protected $adviceMethodName;
    /** @var boolean Used to negate the pointcut expression */
    protected $negate;
    /** @var string The pointcut pattern used to match the methods */
    protected $pointcutPattern;

    /**
     * Creates a new pointcut with the given arguments
     *
     * @param string $aspectClassName The name of the aspect class
     * @param string $adviceMethodName The name of the advice method
     * @param boolean $negate Used to negate the pointcut expression
     * @param string $pointcutPattern An optional pointcut pattern
     */
    public function __construct($aspectClassName, $adviceMethodName, $negate = false, $pointcutPattern = '') {
        $this->aspectClassName = $aspectClassName;
        $this->adviceMethodName = $adviceMethodName;
        $this->negate = $negate;
        $this->pointcutPattern = $pointcutPattern;

        $this->initialize($pointcutPattern);
    }

    /**
     * Initializes the current pointcut with the given pointcut pattern
     *
     * @param string $pointcutPattern The poincut pattern
     */
    protected function initialize($pointcutPattern) {

    }

    /**
     * Checks if the specified $methodName from the given $className matches
     * with the requested $pointcut
     *
     * @param aspectJoinpoint $joinpoint The current joinpoint to match
     * @return boolean Returns true if the pointcut matches
     */
    abstract public function matches(aspectJoinpoint $joinpoint);

    /**
     * @return string The name of the aspect class
     */
    public function getAspectClassName() {
        return $this->aspectClassName;
    }

    /**
     * @return string The name of the advice method
     */
    public function getAdviceMethodName() {
        return $this->adviceMethodName;
    }

}
